/*******************************************************************

   ModuleEntry.c

   Since we want now that DOpus does start our module on its startup,
	we need to modify one flag (MODULE_FLAGS). This would be to do in
	the includes/Project.h, but it's also possible here.

*********************************************************************/

#define PARENT
#include "/includes/Project.h"


ModuleInfo module_info =
{
    MODULE_VER_NUMBER,
    MODULE_NAME,
    MODULE_CATALOG,
    MODULE_FLAGS | MODULEF_CALL_STARTUP, // Here we add the needed flag
    MODULE_FUNC_COUNT,

    { FUNC0_ID, COMMAND_0, FUNC0_DESCRIPTION, FUNC0_FLAGS, FUNC0_TEMPLATE }
};

// now you must modify some lines, if your module should have more than
// one command buildin...
// For example we make here at all 3 commands. The 3. command itself is a
// hidden command (is not shown in the commandlist...)

#if MODULE_FUNC_COUNT-1

ModuleFunction module_func[MODULE_FUNC_COUNT-1] =
{ 
    { FUNC1_ID, COMMAND_1, FUNC1_DESCRIPTION, FUNC1_FLAGS, FUNC1_TEMPLATE },
    { FUNC2_ID, COMMAND_2, FUNC2_DESCRIPTION, FUNC2_FLAGS, FUNC2_TEMPLATE }
};

#endif


// If you are a really nice programmer, you should provide the version
// string with some extra \0 's...

static char version[] = "\0$VER: " VERSION_STRING " " __AMIGADATE__ "\0";

/********************************************************************/
// Now we are ready to enter our program code...

int __asm __saveds L_Module_Entry( register __a0 char *args,              
                                   register __a1 struct Screen *screen,   
                                   register __a2 IPCData *ipc,
                                   register __a3 IPCData *main_ipc,
                                   register __d0 ULONG mod_id,
                                   register __d1 EXT_FUNC(func_callback) )
{  
	 // now we can (should) get an special value for mod_id
	 // as action we do here launch one of our commands (the requester)
	 // it will be done with EXT_FUNC() as ARexx command
	 // since it will be launched async, we have already one chance
	 // to detach an own process...
	 
	 // NOTE: If you use the MODULEF_STARTUP flag you'll get in some
	 // cases no valid screenpointer !! (not mentioned in the SDK)
	 
	 // at first we need a structure to call the func_callback()
	 
	 struct command_packet cp;
	 	 	              
    switch( mod_id )
      {
          case FUNC0_ID :  ExampleRequest( args, screen, ipc );
                           break;

          case FUNC1_ID :  OwnWindow( args, screen );
                           break;

          case FUNC2_ID :  HiddenCommand( args, ipc, main_ipc );
                           break;
									
			 case FUNCID_STARTUP:
			                  
									// now fill the command_packet
									cp.command = "command Beep"; //ExampleRequest Called on Startup";
									// refer also the ARexx description of DOpus
									
									cp.flags = COMMANDF_RESULT;
									cp.result = NULL;									
									
									// and do the command
									
									func_callback( EXTCMD_SEND_COMMAND, IPCDATA(ipc), &cp );
									
									if( cp.result )
									     FreeVec( cp.result );
									
									break;
      }

    return 1;
}